package com.bhkj.pdjhforotherapp.core.jhaudio;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.ServiceUtils;
import com.blankj.utilcode.util.ToastUtils;

public class AudioReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (Intent.ACTION_HEADSET_PLUG.equals(action)) {
            if (intent.hasExtra("state")) {
                final int state = intent.getIntExtra("state", 0);
                if (state == 1) {
                    //插入耳机
                    ToastUtils.showShort("插入耳机");
                    ServiceUtils.startService(JhAudioService.class);
                } else if (state == 0) {
                    //拔出耳机
                    ToastUtils.showShort("拔出耳机");
                    ServiceUtils.stopService(JhAudioService.class);
                }
            }
        }
    }


}
